package com.hoperun.callsystem.adapter

import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hopedove.callsystem.R
import com.hoperun.callsystem.entity.CarEntity


class CarAdapter(type: Int) :
    BaseQuickAdapter<CarEntity, BaseViewHolder>(R.layout.item_car_layout) {
    val mType = type
    var selection = -1
    override fun convert(helper: BaseViewHolder, item: CarEntity?) {

        val whlocNoTv = helper.getView<TextView>(R.id.whlocNoTv)
        whlocNoTv.text = item?.WHLOCNO


        when (mType) {
            //检验区
            1 -> {
                whlocNoTv.background =
                    ContextCompat.getDrawable(mContext, R.drawable.btn_corner_green_light_5)
            }
            //生产区
            2 -> {
                whlocNoTv.background =
                    ContextCompat.getDrawable(mContext, R.drawable.btn_corner_yellow_light_5)
            }
            //退托盘
            3 -> {
                //1是可选 0 不可选
                if (item?.OCCFLAG == "0") {
                    whlocNoTv.background =
                        ContextCompat.getDrawable(mContext, R.drawable.btn_corner_green_light_5)
                    whlocNoTv.isClickable = false
                    // whlocNoTv.isFocusable=false
                } else {
                    whlocNoTv.background =
                        ContextCompat.getDrawable(mContext, R.drawable.btn_corner_yellow_light_5)
                    whlocNoTv.isClickable = true
                }
            }
        }

        if (selection == helper.adapterPosition) {
            when (mType) {
                1 -> {
                    whlocNoTv.background =
                        ContextCompat.getDrawable(mContext, R.drawable.btn_corner_green_dark_5)
                }
                2 -> {
                    whlocNoTv.background =
                        ContextCompat.getDrawable(mContext, R.drawable.btn_corner_yellow_dark_5)
                }
                3 -> {
                    whlocNoTv.background =
                        ContextCompat.getDrawable(mContext, R.drawable.btn_corner_yellow_dark_5)
                }
            }

        }


    }


    fun setCurrent(position: Int) {
        val temp = selection
        selection = position
        notifyItemChanged(selection)
        notifyItemChanged(temp)
    }
}